# -*- coding;utf-8 -*-
from mysql_utility.table import TableBase
from logger_utility.loggconfig import getLogger, LoggerConfig, DEBUG
import requests

logger = getLogger("Del_NEWS_BATCH")


ONLINE_CMS_COPY = {
    'host': 'rdsu2r0v572z8cg70cnd.mysql.rds.aliyuncs.com',
    'user': 'thecover',
    'passwd': 'Thecover_2016',
    'db': 'fmcm_cms',
    'charset': 'utf8',
}

table = TableBase(
    'tmp',
    'id',
    db_config=ONLINE_CMS_COPY
)


def get_news(news_id):
    sql = "select * from fm_news_newscontent where news_id={}".format(news_id)
    ret = table._exce_sql(sql)
    return ret[0]


def delete_news(news_id):
    content = get_news(news_id)['content']
    dict_ = {
        'keys': [news_id],
        'texts': [content]
    }
    try:
        ret = requests.post('http://127.0.0.1:10014/del_news_batch', json=dict_)
        ret_dict_ = ret.json()
        return ret_dict_

    except Exception as e:
        logger.exception(e)


if __name__ == '__main__':
    LoggerConfig().config(True, DEBUG)
    delete_news(658442)


